package cate.game.role.task.conditiontask;

import cate.common.table.d.GDHistory;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ConditionInitValue {
    private ConditionInitValue(){}

    public static void initOnCreate(ConditionPO condition){
        try {
            switch (condition.getRow().event) {
                case GDHistory.Event.RUNE_RECAST_RANDOM_TIMES:
                case GDHistory.Event.EQUIP_LEVEL_UP_RANDOM_TIMES:
                    condition.value = randomInit(3, condition.getRow().value);
                    break;
                default:
                    break;
            }
        } catch (Exception e) {
            log.error("大概率是因为找不到tid={}的任务", condition.tId);
        }
    }

    private static long randomInit(int leastValue, long maxValue){
        if(maxValue < leastValue){
            return 0;
        }
        for (int i=leastValue; i<maxValue; ++i) {
            if(Math.random() <= 0.05){
                return maxValue - leastValue + 1;
            }
        }
        return 0;
    }
}
